class LStack:
    """基于list实现"""

    def __init__(self) -> None:
        self.items = []

    def isEmpty(self) -> bool:
        return 0 == len(self.items)

    def push(self, item):
        self.items.append(item)

    def pop(self):
        return self.items.pop()

    def peek(self):
        return self.items[len(self.items) - 1]

    def size(self) -> int:
        return len(self.items)


from collections import deque


class Stack:
    """dequeue实现"""

    def __init__(self) -> None:
        self.items = deque()

    def empty(self) -> bool:
        return 0 == len(self.items)

    def push(self, item):
        self.items.append(item)

    def pop(self):
        if len(self.items) > 0:
            return self.items.pop()
        else:
            print("栈为空！")
            return None

    def top(self):
        return self.items[len(self.items) - 1]

    def size(self) -> int:
        return len(self.items)

    def __len__(self) -> int:
        return len(self.items)


class Queue:
    """dequeue实现"""

    def __init__(self):
        self.items = deque()

    def enqueue(self, item):
        self.items.append(item)

    def dequeque(self):
        if len(self.items) > 0:
            return self.items.popleft()
        else:
            print("队列为空！")
            return None

    def empty(self):
        return 0 == len(self.items)

    def __len__(self) -> int:
        return len(self.items)

    def size(self) -> int:
        return len(self.items)


class Deque:
    def __init__(self):
        self.items = deque()

    def add_front(self, item):
        self.items.appendleft(item)

    def add_rear(self, item):
        self.items.append(item)

    def remove_front(self):
        if not self.empty():
            return self.items.popleft()
        print("队列为空，移除失败")
        return None

    def remove_rear(self):
        if not self.empty():
            return self.items.pop()
        print("队列为空，移除失败")
        return None

    def empty(self) -> bool:
        return 0 == len(self.items)

    def size(self) -> int:
        return len(self.items)

    def __len__(self) -> int:
        return len(self.items)
